/**********************************************************************
  The MIT License (MIT)
  Copyright (c) 2012 sunriseyuen

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************/

#define _DEF_CCY_CODE
#define _ZZDEBUG
#define _PROJ_DC

#region Using directives
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;

using Muki.Framework.Util;
using Muki.Framework.Business;
using Muki.Framework;
using Muki.UserDefine;
using Muki.Entity;
using Dot.StreamObject;

#endregion

namespace Muki.UserPanel
{
	public class UID02811BM:BLogic
	{
		public UID02811BM()
		{
			objDefault.UID_CODE    ="UID02811B";
		}

		public void Initialize()
		{
			objDefault.ZZLOGON_SSD = this.ZZLOGON_SSD;
			objDefault.Trans       = this.Trans;
			objDefault.ZZLOGON_ID  = this.ZZLOGON_ID;

			_Convert.ZZLOGON_SSD = this.ZZLOGON_SSD;
			_Convert.Trans       = this.Trans;

			_DataPermission.ZZLOGON_SSD = this.ZZLOGON_SSD;
			_DataPermission.Trans       = this.Trans;
			_DataPermission.TABLE_NAME  = "FGNDTLM";
			_DataPermission.ZZLOGON_ID  = this.ZZLOGON_ID;
			_DataPermission.DataAccessRight();

			_DocsPermission.ZZLOGON_SSD  = this.ZZLOGON_SSD;
			_DocsPermission.Trans        = this.Trans;

			_Setting.ZZLOGON_ID = this.ZZLOGON_ID;
			_Setting.Trans      = this.Trans;

		}

		public UID02811BE Verify(UID02811BE _Entity)
		{

						_Entity.FG_DT=_Entity.FG_DT.Trim();

					if (Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
					{
						_Entity.Exceptions.Add(new LogisticException("TRANS_WO_NO","DataMiss"));
					}

					if (Util.IsNullOrEmpty(_Entity.TRANS_QTY))
					{
						_Entity.Exceptions.Add(new LogisticException("TRANS_QTY","DataMiss"));
					}

					if (Util.IsNullOrEmpty(_Entity.REFX_NO))
					{
						_Entity.Exceptions.Add(new LogisticException("REFX_NO","DataMiss"));
					}

				// Relation FGNHDTM
			if (!Util.IsNullOrEmpty(_Entity.FG_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(FGNHDTMEntity));//FGNHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("FG_NO",_Entity.FG_NO);
				_DataPermission.TABLE_NAME="FGNHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("FG_NO","DataNotFd",_Entity.FG_NO));
			}else{

					FGNHDTMEntity objVFGNHDTMEntity=(FGNHDTMEntity)objEntityContainer[0];
					if (objVFGNHDTMEntity.Verified)
					{
						 _Entity.FG_NO=objVFGNHDTMEntity.FG_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("FG_NO","DataNotFd",_Entity.FG_NO));
					}
			}
			}
//FGNHDTM

				// Relation WORHDTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORHDTMEntity));//工作单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_NO",_Entity.TRANS_WO_NO);
				_DataPermission.TABLE_NAME="WORHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_WO_NO","DataNotFd",_Entity.TRANS_WO_NO));
			}else{

					WORHDTMEntity objVWORHDTMEntity=(WORHDTMEntity)objEntityContainer[0];
					if (objVWORHDTMEntity.Verified)
					{
						 _Entity.TRANS_WO_NO=objVWORHDTMEntity.WO_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_WO_NO","DataNotFd",_Entity.TRANS_WO_NO));
					}
			}
			}
//WORHDTM

				// Relation PARTBLM
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
			}else{

					PARTBLMEntity objVPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objVPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objVPARTBLMEntity.ITEM_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
					}
			}
			}
//PARTBLM

				// Relation PARTBLM
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
			}else{

					PARTBLMEntity objVPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objVPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objVPARTBLMEntity.ITEM_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
					}
			}
			}
//PARTBLM

				// Relation UOMTBLM
			if (!Util.IsNullOrEmpty(_Entity.UOM_CODE))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(UOMTBLMEntity));//单位资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("UOM_CODE",_Entity.UOM_CODE);
				_DataPermission.TABLE_NAME="UOMTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("UOM_CODE","DataNotFd",_Entity.UOM_CODE));
			}else{

					UOMTBLMEntity objVUOMTBLMEntity=(UOMTBLMEntity)objEntityContainer[0];
					if (objVUOMTBLMEntity.Verified)
					{
						 _Entity.UOM_CODE=objVUOMTBLMEntity.UOM_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("UOM_CODE","DataNotFd",_Entity.UOM_CODE));
					}
			}
			}
//UOMTBLM

				// Relation WHLOCTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX1))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WHLOCTMEntity));//仓位资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("LOC_CODE",_Entity.TRANS_UDFX1);
			objCondition.Equals("WH_CODE",_Entity.WH_CODE);
				_DataPermission.TABLE_NAME="WHLOCTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX1","DataNotFd",_Entity.TRANS_UDFX1));
			}else{

					WHLOCTMEntity objVWHLOCTMEntity=(WHLOCTMEntity)objEntityContainer[0];
					if (objVWHLOCTMEntity.Verified)
					{
						 _Entity.TRANS_UDFX1=objVWHLOCTMEntity.LOC_CODE;
						 _Entity.WH_CODE=objVWHLOCTMEntity.WH_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX1","DataNotFd",_Entity.TRANS_UDFX1));
					}
			}
			}
//WHLOCTM

				// Relation COLORTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX3))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(COLORTMEntity));//颜色码资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("COLOR_CODE",_Entity.TRANS_UDFX3);
				_DataPermission.TABLE_NAME="COLORTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX3","DataNotFd",_Entity.TRANS_UDFX3));
			}else{

					COLORTMEntity objVCOLORTMEntity=(COLORTMEntity)objEntityContainer[0];
					if (objVCOLORTMEntity.Verified)
					{
						 _Entity.TRANS_UDFX3=objVCOLORTMEntity.COLOR_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX3","DataNotFd",_Entity.TRANS_UDFX3));
					}
			}
			}
//COLORTM

				// Relation SIZECDM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX4))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(SIZECDMEntity));//尺寸资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("SIZE_CODE",_Entity.TRANS_UDFX4);
				_DataPermission.TABLE_NAME="SIZECDM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX4","DataNotFd",_Entity.TRANS_UDFX4));
			}else{

					SIZECDMEntity objVSIZECDMEntity=(SIZECDMEntity)objEntityContainer[0];
					if (objVSIZECDMEntity.Verified)
					{
						 _Entity.TRANS_UDFX4=objVSIZECDMEntity.SIZE_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX4","DataNotFd",_Entity.TRANS_UDFX4));
					}
			}
			}
//SIZECDM

				return _Entity;
		}

		public List<UID02811BE> Verify(List<UID02811BE> _Entitys)
		{
			List<UID02811BE> _New_Entitys=new List<UID02811BE>();

			foreach (UID02811BE _Entity in _Entitys) 
			{
				_New_Entitys.Add(Verify(_Entity));
			}
			return _New_Entitys;
		}

		public UID02811BE Default(UID02811BE _Entity)
		{

						_Entity.FG_DT=objDefault.getDefault("FG_DT",_Entity.FG_DT);
						_Entity.COMP_CODE=objDefault.getDefault("COMP_CODE",_Entity.COMP_CODE);
						_Entity.SERIAL_NO=objDefault.getDefault("SERIAL_NO",_Entity.SERIAL_NO);
						_Entity.TRANS_CODE=objDefault.getDefault("TRANS_CODE",_Entity.TRANS_CODE);
						_Entity.WH_CODE=objDefault.getDefault("WH_CODE",_Entity.WH_CODE);
						_Entity.TRANS_DATE=objDefault.getDefault("TRANS_DATE",_Entity.TRANS_DATE);
						_Entity.TRANS_WO_NO=objDefault.getDefault("TRANS_WO_NO",_Entity.TRANS_WO_NO);
						_Entity.CTR_CODE=objDefault.getDefault("CTR_CODE",_Entity.CTR_CODE);
						_Entity.REQ_QTY=objDefault.getDefault("REQ_QTY",_Entity.REQ_QTY);
						_Entity.XFG_QTY=objDefault.getDefault("XFG_QTY",_Entity.XFG_QTY);
						_Entity.ITEM_NO=objDefault.getDefault("ITEM_NO",_Entity.ITEM_NO);
						_Entity.ITEM_NAME01=objDefault.getDefault("ITEM_NAME01",_Entity.ITEM_NAME01);
						_Entity.UOM_CODE=objDefault.getDefault("UOM_CODE",_Entity.UOM_CODE);
						_Entity.ITEM_NAME02=objDefault.getDefault("ITEM_NAME02",_Entity.ITEM_NAME02);
						_Entity.TRANS_UDFX1=objDefault.getDefault("TRANS_UDFX1",_Entity.TRANS_UDFX1);
						_Entity.TRANS_UDFX3=objDefault.getDefault("TRANS_UDFX3",_Entity.TRANS_UDFX3);
						_Entity.TRANS_UDFX4=objDefault.getDefault("TRANS_UDFX4",_Entity.TRANS_UDFX4);
						_Entity.TRANS_QTY=objDefault.getDefault("TRANS_QTY",_Entity.TRANS_QTY);
						_Entity.REFX_NO=objDefault.getDefault("REFX_NO",_Entity.REFX_NO);
						_Entity.TRANS_RMK=objDefault.getDefault("TRANS_RMK",_Entity.TRANS_RMK);

					// WriteDefault FGNHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.FG_NO="+_Entity.FG_NO);
			if (!Util.IsNullOrEmpty(_Entity.FG_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(FGNHDTMEntity));//FGNHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("FG_NO",_Entity.FG_NO);
				_DataPermission.TABLE_NAME="FGNHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"FGNHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					FGNHDTMEntity objDFGNHDTMEntity=(FGNHDTMEntity)objEntityContainer[0];
					if (objDFGNHDTMEntity.Verified)
					{
						 _Entity.FG_NO=objDFGNHDTMEntity.FG_NO;
						 _Entity.COMP_CODE=objDFGNHDTMEntity.COMP_CODE;
						 _Entity.REFX_NO=objDFGNHDTMEntity.REFX_NO;
						 _Entity.TRANS_CODE=objDFGNHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDFGNHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDFGNHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

					// WriteDefault WORHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORHDTMEntity));//工作单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_NO",_Entity.TRANS_WO_NO);
				_DataPermission.TABLE_NAME="WORHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORHDTMEntity objDWORHDTMEntity=(WORHDTMEntity)objEntityContainer[0];
					if (objDWORHDTMEntity.Verified)
					{
						 _Entity.TRANS_WO_NO=objDWORHDTMEntity.WO_NO;
						 _Entity.XFG_QTY=objDWORHDTMEntity.ASSM_FG_QTY;
						 _Entity.REQ_QTY=objDWORHDTMEntity.ASSM_REQ_QTY;
						 _Entity.CTR_CODE=objDWORHDTMEntity.CTR_CODE;
						 _Entity.ITEM_NO=objDWORHDTMEntity.ITEM_NO;

					}else{
					}
			}else{
			}
			}

					// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

					// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

				return _Entity;
		}

		public List<UID02811BE> Default(List<UID02811BE> _Entitys)
		{
			List<UID02811BE> _New_Entitys=new List<UID02811BE>();
			foreach (UID02811BE _Entity in _Entitys) 
			{
				_New_Entitys.Add(Default(_Entity));
			}
			return _New_Entitys;
		}

		public UID02811BE Search(VContexts _VContexts,UID02811BE _Entity)
		{

			if (_DocsPermission.AccessRight("UID02811B", this.ZZLOGON_ID, "ACCESS")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02811B","NotAccessRight", this.ZZLOGON_ID));
				return _Entity;
			}

			ZZSQLStatement  _SQLStatement = new ZZSQLStatement();

			_SQLStatement.Trans         = this.Trans;
			_SQLStatement.UID_CODE      = "UID02811B";
			_SQLStatement.ZZLOGON_SSD   = this.ZZLOGON_SSD;
			_SQLStatement.ZZLOGON_LANG  = this.ZZLOGON_LANG;
			_SQLStatement.DbName        = this.DbName;
			_SQLStatement.Process("QID02811B");

			ZZQLite oZZQLite = _SQLStatement.oZZQLite;

			if (_VContexts.getValue("T1")!="" && _VContexts.getValue("V1")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T1"), _VContexts.getValue("V1"));
			}
			if (_VContexts.getValue("T2")!="" && _VContexts.getValue("V2")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T2"), _VContexts.getValue("V2"));
			}
			if (_VContexts.getValue("T3")!="" && _VContexts.getValue("V3")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T3"), _VContexts.getValue("V3"));
			}

			if (!Util.IsNullOrEmpty(_VContexts.getValue("lookup")))
			{
				oZZQLite.AddXWhereClause("A", "", _VContexts.getValue("lookup"));
			}

						_VContexts.setValue("TT1","FGNDTLM.FG_NO");
						_VContexts.setValue("VV1",_Entity.FG_NO);
						oZZQLite.AddWhereClause("FGNDTLM", "FG_NO", _Entity.FG_NO);

			oZZQLite.Condition=_VContexts.getValue("Condition");
			oZZQLite.Make();

			int _AbsolutePage = _VContexts.getInteger("AbsolutePage");
			int _PageSize     = _VContexts.getInteger("ZZPageSize");
			int _Restrict     = _VContexts.getInteger("Restrict");
			int _TotalPages   = 0;

			_Setting.Trans      = this.Trans;

			if (_Restrict == 0)
			{
				_Restrict=30;
			}

			if (_PageSize <= 0)
			{
				_PageSize=_Setting.getInteger("ZZPageSize","20");
			}

				QueryRows RsFGNDTLM   = new QueryRows(this.Trans);
			RsFGNDTLM.CommandText = oZZQLite.SQLStatement;
			RsFGNDTLM.Top         = _Restrict;
			RsFGNDTLM.Skip        = (_AbsolutePage-1)*_PageSize;
			RsFGNDTLM.Limit       = _PageSize;
			RsFGNDTLM.CountAll    = true;
			RsFGNDTLM.Open();

			if (_PageSize <= 0)
			{
				_TotalPages   = RsFGNDTLM.RecordCount;
				_PageSize = RsFGNDTLM.RecordCount;
			}
			else
			{
				_TotalPages= RsFGNDTLM.RecordCount / _PageSize;
			}
			if (RsFGNDTLM.RecordCount > (RsFGNDTLM.RecordCount / _PageSize) * _PageSize)
			{
				_TotalPages = _TotalPages+ 1;
			}

			if (_AbsolutePage <= 0)
			{
				_AbsolutePage = 1;
			}

			if (_AbsolutePage > _TotalPages)
			{
				_AbsolutePage = _TotalPages;
			}

			Wxf _Wxf  = new Wxf();

			_Wxf.XDeclareStart();
			foreach(AttributeMapping _AttributeMapping in oZZQLite.AttributeMappings)
			{
				if (_AttributeMapping.STATUS_CODE != "HIDDEN")
				{
					_Wxf.XDeclare(_AttributeMapping);
				}
			}
			_Wxf.XDeclareFinal();

			_Wxf.Variable("ZZPageSize",_PageSize);
			_Wxf.Variable("ZZPages",_TotalPages);
			_Wxf.Variable("USQL_CODE","QID02811B");

			while (!RsFGNDTLM.EOF)
			{
				string cPickUpData   = "";
				object cValue;

				_Wxf.AddNew();
				int i=0;
				foreach(AttributeMapping _AttributeMapping in oZZQLite.AttributeMappings)
				{

					cValue = RsFGNDTLM[i];

					if (_AttributeMapping.STATUS_CODE != "HIDDEN")
					{
						_Wxf[_AttributeMapping.Name] = cValue;
					}

					if (_AttributeMapping.PrimaryKey)
					{
						if (cPickUpData != "")
						{
							cPickUpData = cPickUpData + "|";
						}
						cPickUpData = cPickUpData + ZZGeneral.Base64Encoder(_AttributeMapping.ColumnName + "=" + cValue);
					}
					i++;
				}

				_Wxf.PK_DATA   = cPickUpData;
				_Wxf.Update();

				RsFGNDTLM.MoveNext();
			}
			RsFGNDTLM.Close();

			_Entity.Wxf=_Wxf;

			return _Entity;
		}

		public UID02811BE Retrieves(VContexts _VContexts,UID02811BE _Entity)
		{
			if (_DocsPermission.AccessRight("UID02811B", this.ZZLOGON_ID, "ACCESS")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02811B","NotAccessRight",this.ZZLOGON_ID));
				return _Entity;
			}

			List<UID02811BE> _New_Entitys=new List<UID02811BE>();

				CriteriaRetrieve objRetrieveFGNDTLMEntity=new CriteriaRetrieve(typeof(FGNDTLMEntity));

			objRetrieveFGNDTLMEntity.Top=1;
			objCondition=objRetrieveFGNDTLMEntity.NewCondition();

			bool ZZOrderByAsc=_Setting.getBoolean("ZZOrderByAsc","YES");
			switch (_VContexts.getValue("UDEF_CODE"))
			{
				case "MF":
					{
						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",ZZOrderByAsc);
						break;
					}
				case "ML":
					{
						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",!ZZOrderByAsc);
						break;
					}
				case "MN":
					{
						if (ZZOrderByAsc)
						{
							objCondition.GreaterThan("FG_DT",_Entity.FG_DT);
						}else{
							objCondition.LessThan("FG_DT",_Entity.FG_DT);
						}
						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",ZZOrderByAsc);
						break;
					}
				case "MP":
					{
						if (ZZOrderByAsc)
						{
							objCondition.LessThan("FG_DT",_Entity.FG_DT);
						}else{
							objCondition.GreaterThan("FG_DT",_Entity.FG_DT);
						}
						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",!ZZOrderByAsc);
						break;
					}
				case "CANCEL":
					{
						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",ZZOrderByAsc);
						_Entity.DATA_STATUS_CODE="Verified";
						break;
					}
				case "LOOKUP":
					{
						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",ZZOrderByAsc);
						break;
					}

				case "ACTIVETAB":
					{
								if (_Entity.FG_DT != "")
								{
									objCondition.Equals("FG_DT", _Entity.FG_DT);
								}

						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",ZZOrderByAsc);
						break;
					}

				case "READ":
					{
								objCondition.Equals("FG_DT", _Entity.FG_DT);
						break;
					}					
				default:
					{
								if (_Entity.FG_DT != "")
								{
									objCondition.Equals("FG_DT", _Entity.FG_DT);
								}
						objRetrieveFGNDTLMEntity.OrderBy("FG_DT",ZZOrderByAsc);

						break;
					}
			}

			//filter by quick look
			string _LOOUP_COLUMN_NAME=";FGNDTLM.FG_NO;FGNDTLM.FG_DT;FGNDTLM.TRANS_WO_NO;FGNDTLM.ITEM_NO;FGNDTLM.UOM_CODE;FGNDTLM.TRANS_UDFX1;FGNDTLM.TRANS_UDFX3;FGNDTLM.TRANS_UDFX4;FGNDTLM.REFX_NO;FGNDTLM.TRANS_RMK";
			string lookup=_VContexts.getValue("lookup");
			_LOOUP_COLUMN_NAME=_LOOUP_COLUMN_NAME+";";
			if (lookup!="")
			{
				Condition _Condition2=objCondition.NewCondition(" AND ");
				foreach (string s in _LOOUP_COLUMN_NAME.Split(new char[] { ';' }))
				{
					if (!string.IsNullOrEmpty(s))
					{
						Condition OrCondition=_Condition2.NewCondition();
						OrCondition.Expression(s,lookup);
					}
				}
			}

			//filter by filters

				//filter by AccessConditions
				_DataPermission.AccessCondition(objCondition);

						objCondition.Equals("FG_NO", _Entity.FG_NO);

			FGNDTLMEntity objFGNDTLMs=(FGNDTLMEntity)this.Trans.RetrieveEntity(objRetrieveFGNDTLMEntity);

			ZZTrace.Debug(ZFILE_NAME,"SELECT="+objRetrieveFGNDTLMEntity.SELECTClause);

			if (objFGNDTLMs==null && _VContexts.getValue("UDEF_CODE")=="MN")
			{
				_Entity.Exceptions.Add(new LogisticException("FG_DT","DataEOF"));
				return _Entity;
			}else if (objFGNDTLMs==null && _VContexts.getValue("UDEF_CODE")=="MP")
			{
				_Entity.Exceptions.Add(new LogisticException("FG_DT","DataBOF"));
				return _Entity;
			}else if (objFGNDTLMs==null && (_VContexts.getValue("UDEF_CODE")=="MF" || _VContexts.getValue("UDEF_CODE")=="ML") )
			{
				_Entity.Exceptions.Add(new LogisticException("FG_DT","DataBlank"));
				return _Entity;
			}else if (objFGNDTLMs==null && _VContexts.getValue("UDEF_CODE")=="LOOKUP")
			{
				/*
				 *if (this.COLUMN_REFX.IndexOf(";")>=0)
				 *{
				 *}else{
				 *    string _T_COLUMN_REFX=this.COLUMN_REFX;
				 *    if (_T_COLUMN_REFX.IndexOf('.') > 0)
				 *    {
				 *        string[] s = _T_COLUMN_REFX.Split(new char[] { '.' });
				 *        _T_COLUMN_REFX=s[1];
				 *    }
				 *    _Entity.Exceptions.Add(new LogisticException(_T_COLUMN_REFX,"DataNotFd","DataBlank"));
				 *    return _Entity;
				 *}
				 */
			}else if (objFGNDTLMs==null && _VContexts.getValue("UDEF_CODE")=="ACTIVETAB")
			{
				//throw new LogisticException("FG_DT","Activetab","");
				//this.Default(_Entity);
			}else if (objFGNDTLMs==null)
			{
				//this.Default(_Entity);
			}else{
				FGNDTLMEntity objFGNDTLMEntity = objFGNDTLMs;
					ZZTrace.MUKI_DEBUG_LOG=true;
						_Entity.FG_NO=objFGNDTLMEntity.FG_NO;
						_Entity.FG_DT=objFGNDTLMEntity.FG_DT;
						_Entity.SERIAL_NO=objFGNDTLMEntity.SERIAL_NO;
						_Entity.TRANS_WO_NO=objFGNDTLMEntity.TRANS_WO_NO;
						_Entity.ITEM_NO=objFGNDTLMEntity.ITEM_NO;
						_Entity.UOM_CODE=objFGNDTLMEntity.UOM_CODE;
						_Entity.TRANS_UDFX1=objFGNDTLMEntity.TRANS_UDFX1;
						_Entity.TRANS_UDFX3=objFGNDTLMEntity.TRANS_UDFX3;
						_Entity.TRANS_UDFX4=objFGNDTLMEntity.TRANS_UDFX4;
						_Entity.TRANS_QTY=objFGNDTLMEntity.TRANS_QTY;
						_Entity.REFX_NO=objFGNDTLMEntity.REFX_NO;
						_Entity.TRANS_RMK=objFGNDTLMEntity.TRANS_RMK;

				_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objFGNDTLMEntity.ZADD_DATE);
_Entity.UZADD_USER     =objFGNDTLMEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objFGNDTLMEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objFGNDTLMEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objFGNDTLMEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objFGNDTLMEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objFGNDTLMEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objFGNDTLMEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objFGNDTLMEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objFGNDTLMEntity.ZSECURITY_CODE6;

					// WriteDefault FGNHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.FG_NO="+_Entity.FG_NO);
			if (!Util.IsNullOrEmpty(_Entity.FG_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(FGNHDTMEntity));//FGNHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("FG_NO",_Entity.FG_NO);
				_DataPermission.TABLE_NAME="FGNHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"FGNHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					FGNHDTMEntity objDFGNHDTMEntity=(FGNHDTMEntity)objEntityContainer[0];
					if (objDFGNHDTMEntity.Verified)
					{
						 _Entity.FG_NO=objDFGNHDTMEntity.FG_NO;
						 _Entity.COMP_CODE=objDFGNHDTMEntity.COMP_CODE;
						 _Entity.TRANS_CODE=objDFGNHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDFGNHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDFGNHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

					// WriteDefault WORHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORHDTMEntity));//工作单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_NO",_Entity.TRANS_WO_NO);
				_DataPermission.TABLE_NAME="WORHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORHDTMEntity objDWORHDTMEntity=(WORHDTMEntity)objEntityContainer[0];
					if (objDWORHDTMEntity.Verified)
					{
						 _Entity.TRANS_WO_NO=objDWORHDTMEntity.WO_NO;
						 _Entity.XFG_QTY=objDWORHDTMEntity.ASSM_FG_QTY;
						 _Entity.REQ_QTY=objDWORHDTMEntity.ASSM_REQ_QTY;
						 _Entity.CTR_CODE=objDWORHDTMEntity.CTR_CODE;
						 _Entity.ITEM_NO=objDWORHDTMEntity.ITEM_NO;

					}else{
					}
			}else{
			}
			}

					// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

					_Entity.DATA_STATUS_CODE="Verified";
			}
				return _Entity;
		}

		public  UID02811BE AddNew(UID02811BE _Entity)
		{

			ZZTrace.Debug(ZFILE_NAME,"ZZLOGON_ID="+this.ZZLOGON_ID);

			if (_DocsPermission.AccessRight("UID02811B", this.ZZLOGON_ID, "ADDNEW")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02811B","NotAddNewRight",this.ZZLOGON_ID));
				return _Entity;
			}

			_Entity.ATVT_CODE="ADDNEW";

				_Entity=this.Verify(_Entity);
			if (_Entity.Exceptions.Count>0)
			{
				return _Entity;
			}
			FGNDTLMEntity objAddNewEntity=new FGNDTLMEntity();

			ZZHDKeyLib objZZHDKeyLib=new ZZHDKeyLib();
			objZZHDKeyLib.Trans=this.Trans;
							objZZHDKeyLib.LNK_COLUMN("FG_NO",_Entity.FG_NO);
							objZZHDKeyLib.LNK_COLUMN_VALUE=_Entity.FG_NO;

				objZZHDKeyLib.PREFIX_CODE="UID02811B";
				objZZHDKeyLib.getSerial("FGNDTLM");
				int XSERIAL_NO=objZZHDKeyLib.PREFIX_CN;

				_Entity.FG_DT=objZZHDKeyLib.DT_NO;

				ZZTrace.Debug(ZFILE_NAME,_Entity.FG_DT);
				ZZTrace.Debug(ZFILE_NAME,XSERIAL_NO);

					objAddNewEntity.FG_DT=_Entity.FG_DT;

			this.Trans.RetrieveEntity(objAddNewEntity);

			if (objAddNewEntity.Verified)
			{
				_Entity.Exceptions.Add(new LogisticException("FG_DT","DataExist",_Entity.FG_DT));
				return _Entity;
			}else{

				objAddNewEntity.ZADD_DATE = DateTime.Now;
				objAddNewEntity.ZADD_USER = this.ZZLOGON_ID;

				_DataPermission.TABLE_NAME="FGNDTLM";
				_DataPermission.DataAccessRight();
				objAddNewEntity.ZSECURITY_CODE1 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE1");
				objAddNewEntity.ZSECURITY_CODE2 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE2");
				objAddNewEntity.ZSECURITY_CODE3 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE3");
				objAddNewEntity.ZSECURITY_CODE4 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE4");
				objAddNewEntity.ZSECURITY_CODE5 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE5");
				objAddNewEntity.ZSECURITY_CODE6 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE6");
				objAddNewEntity.ZSECURITY_RIGHT = _DataPermission.ACCESS_AUTH.getInteger("SECURITY_RIGHT");

				_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objAddNewEntity.ZADD_DATE);
_Entity.UZADD_USER     =objAddNewEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objAddNewEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objAddNewEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objAddNewEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objAddNewEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objAddNewEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objAddNewEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objAddNewEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objAddNewEntity.ZSECURITY_CODE6;

							objAddNewEntity.FG_NO=_Entity.FG_NO;
							objAddNewEntity.FG_DT=_Entity.FG_DT;
							objAddNewEntity.SERIAL_NO=_Entity.SERIAL_NO;
							objAddNewEntity.TRANS_WO_NO=_Entity.TRANS_WO_NO;
							objAddNewEntity.ITEM_NO=_Entity.ITEM_NO;
							objAddNewEntity.UOM_CODE=_Entity.UOM_CODE;
							objAddNewEntity.TRANS_UDFX1=_Entity.TRANS_UDFX1;
							objAddNewEntity.TRANS_UDFX3=_Entity.TRANS_UDFX3;
							objAddNewEntity.TRANS_UDFX4=_Entity.TRANS_UDFX4;
							objAddNewEntity.TRANS_QTY=_Entity.TRANS_QTY;
							objAddNewEntity.REFX_NO=_Entity.REFX_NO;
							objAddNewEntity.TRANS_RMK=_Entity.TRANS_RMK;
					ZZTrace.Debug(ZFILE_NAME,XSERIAL_NO);

					objAddNewEntity.SERIAL_NO=XSERIAL_NO;
					_Entity.SERIAL_NO=XSERIAL_NO;
			}

				this.Trans.SaveChanges(objAddNewEntity);

				// WriteDefault FGNHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.FG_NO="+_Entity.FG_NO);
			if (!Util.IsNullOrEmpty(_Entity.FG_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(FGNHDTMEntity));//FGNHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("FG_NO",_Entity.FG_NO);
				_DataPermission.TABLE_NAME="FGNHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"FGNHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					FGNHDTMEntity objDFGNHDTMEntity=(FGNHDTMEntity)objEntityContainer[0];
					if (objDFGNHDTMEntity.Verified)
					{
						 _Entity.FG_NO=objDFGNHDTMEntity.FG_NO;
						 _Entity.COMP_CODE=objDFGNHDTMEntity.COMP_CODE;
						 _Entity.TRANS_CODE=objDFGNHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDFGNHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDFGNHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

				// WriteDefault WORHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORHDTMEntity));//工作单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_NO",_Entity.TRANS_WO_NO);
				_DataPermission.TABLE_NAME="WORHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORHDTMEntity objDWORHDTMEntity=(WORHDTMEntity)objEntityContainer[0];
					if (objDWORHDTMEntity.Verified)
					{
						 _Entity.TRANS_WO_NO=objDWORHDTMEntity.WO_NO;
						 _Entity.XFG_QTY=objDWORHDTMEntity.ASSM_FG_QTY;
						 _Entity.REQ_QTY=objDWORHDTMEntity.ASSM_REQ_QTY;
						 _Entity.CTR_CODE=objDWORHDTMEntity.CTR_CODE;
						 _Entity.ITEM_NO=objDWORHDTMEntity.ITEM_NO;

					}else{
					}
			}else{
			}
			}

				// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

				_Entity.DATA_STATUS_CODE="Verified";
			return _Entity;
		}

		public  UID02811BE Update(UID02811BE _Entity)
		{

			if (_DocsPermission.AccessRight("UID02811B", this.ZZLOGON_ID, "UPDATE")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02811B","NotUpdateRight",this.ZZLOGON_ID));
				return _Entity;
			}
			_Entity.ATVT_CODE="UPDATE";

						if (_Entity.FG_DT=="")
						{
							_Entity.Exceptions.Add(new LogisticException("FG_DT","DataMiss",""));
						}

			_Entity=this.Verify(_Entity);
			ZZTrace.Debug(ZFILE_NAME,"_Entity.Exceptions.Count="+_Entity.Exceptions.Count);
			if (_Entity.Exceptions.Count>0)
			{
				return _Entity;
			}

					//ZZTrace.Debug(ZFILE_NAME,"_Entity.FG_NO="+_Entity.FG_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.FG_DT="+_Entity.FG_DT);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.SERIAL_NO="+_Entity.SERIAL_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.UOM_CODE="+_Entity.UOM_CODE);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX1="+_Entity.TRANS_UDFX1);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX3="+_Entity.TRANS_UDFX3);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX4="+_Entity.TRANS_UDFX4);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_QTY="+_Entity.TRANS_QTY);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.REFX_NO="+_Entity.REFX_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_RMK="+_Entity.TRANS_RMK);

			objRetrieveEntity=new CriteriaRetrieve(typeof(FGNDTLMEntity));
			objCondition=objRetrieveEntity.NewCondition();

					objCondition.Equals("FG_DT", _Entity.FG_DT);

			_DataPermission.UpdateCondition(objCondition);

			EntityObject objEntityObject=this.Trans.RetrieveEntity(objRetrieveEntity);

			if (objEntityObject != null)
			{
				FGNDTLMEntity objUpdateEntity=(FGNDTLMEntity)objEntityObject;
				if (objUpdateEntity.Verified)
				{
					objUpdateEntity.ZCHG_DATE=DateTime.Now;
					objUpdateEntity.ZCHG_USER=this.ZZLOGON_ID;

								objUpdateEntity.FG_NO=_Entity.FG_NO;
								objUpdateEntity.FG_DT=_Entity.FG_DT;
								objUpdateEntity.SERIAL_NO=_Entity.SERIAL_NO;
								objUpdateEntity.TRANS_WO_NO=_Entity.TRANS_WO_NO;
								objUpdateEntity.ITEM_NO=_Entity.ITEM_NO;
								objUpdateEntity.UOM_CODE=_Entity.UOM_CODE;
								objUpdateEntity.TRANS_UDFX1=_Entity.TRANS_UDFX1;
								objUpdateEntity.TRANS_UDFX3=_Entity.TRANS_UDFX3;
								objUpdateEntity.TRANS_UDFX4=_Entity.TRANS_UDFX4;
								objUpdateEntity.TRANS_QTY=_Entity.TRANS_QTY;
								objUpdateEntity.REFX_NO=_Entity.REFX_NO;
								objUpdateEntity.TRANS_RMK=_Entity.TRANS_RMK;

						this.Trans.SaveChanges(objUpdateEntity);

						// WriteDefault FGNHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.FG_NO="+_Entity.FG_NO);
			if (!Util.IsNullOrEmpty(_Entity.FG_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(FGNHDTMEntity));//FGNHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("FG_NO",_Entity.FG_NO);
				_DataPermission.TABLE_NAME="FGNHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"FGNHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					FGNHDTMEntity objDFGNHDTMEntity=(FGNHDTMEntity)objEntityContainer[0];
					if (objDFGNHDTMEntity.Verified)
					{
						 _Entity.FG_NO=objDFGNHDTMEntity.FG_NO;
						 _Entity.COMP_CODE=objDFGNHDTMEntity.COMP_CODE;
						 _Entity.TRANS_CODE=objDFGNHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDFGNHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDFGNHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

						// WriteDefault WORHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORHDTMEntity));//工作单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_NO",_Entity.TRANS_WO_NO);
				_DataPermission.TABLE_NAME="WORHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORHDTMEntity objDWORHDTMEntity=(WORHDTMEntity)objEntityContainer[0];
					if (objDWORHDTMEntity.Verified)
					{
						 _Entity.TRANS_WO_NO=objDWORHDTMEntity.WO_NO;
						 _Entity.XFG_QTY=objDWORHDTMEntity.ASSM_FG_QTY;
						 _Entity.REQ_QTY=objDWORHDTMEntity.ASSM_REQ_QTY;
						 _Entity.CTR_CODE=objDWORHDTMEntity.CTR_CODE;
						 _Entity.ITEM_NO=objDWORHDTMEntity.ITEM_NO;

					}else{
					}
			}else{
			}
			}

						// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

						_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objUpdateEntity.ZADD_DATE);
_Entity.UZADD_USER     =objUpdateEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objUpdateEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objUpdateEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objUpdateEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objUpdateEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objUpdateEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objUpdateEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objUpdateEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objUpdateEntity.ZSECURITY_CODE6;

					_Entity.DATA_STATUS_CODE="Verified";

				}else{
					_Entity.Exceptions.Add(new LogisticException("FG_DT","DataNotFd"));
				}
			}else{
				_Entity.Exceptions.Add(new LogisticException("FG_DT","DataNotFd"));
			}
			return _Entity;
		}

		public  UID02811BE Delete(UID02811BE _Entity)
		{
			if (_DocsPermission.AccessRight("UID02811B", this.ZZLOGON_ID, "DELETE")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02811B","NotDeleteRight"));
				return _Entity;
			}
			_Entity.ATVT_CODE="DELETE";

					if (_Entity.FG_DT=="")
					{
						_Entity.Exceptions.Add(new LogisticException("FG_DT","DataMiss"));
						return _Entity;
					}

				objRetrieveEntity=new CriteriaRetrieve(typeof(FGNDTLMEntity));
			objCondition=objRetrieveEntity.NewCondition();

					objCondition.Equals("FG_DT", _Entity.FG_DT);

			_DataPermission.DeleteCondition(objCondition);

			EntityObject objDeleteEntity=this.Trans.RetrieveEntity(objRetrieveEntity);

			if (objDeleteEntity != null)
			{
				if (objDeleteEntity.Verified)
				{
						this.Trans.DeleteEntity(objDeleteEntity);
						StringBuilder delete_cmd=new StringBuilder(this.ZZLOGON_ID+"UID02811B-DELETED=");
							delete_cmd.Append("FG_DT="+_Entity.FG_DT);

					ZZTrace.Debug("DELETED_LOG",delete_cmd.ToString());

				}else{
					_Entity.Exceptions.Add(new LogisticException("FG_DT","DataNotFd"));
					return _Entity;
				}
			}else{
				_Entity.Exceptions.Add(new LogisticException("FG_DT","DataNotFd"));
			}
			return _Entity;

		}

		public UID02811BE UserDefine(VContexts cMethod,UID02811BE _Entity)
		{
				return _Entity;
		}

#region Field
			private CriteriaRetrieve objRetrieveEntity;
		private List<EntityObject>  objEntityContainer;
		private Condition        objCondition;
		private ZZDefault        objDefault      = new ZZDefault();
		private ZZDataPermission _DataPermission = new ZZDataPermission();
		private ZZDocsPermission _DocsPermission = new ZZDocsPermission();
		private ZZSetting        _Setting        = new ZZSetting();
		private XConvert         _Convert        = new XConvert();

#endregion

			const  string ZFILE_NAME   ="UID02811BM";
		const  string MUKI_EDITION ="MIN";

	}
}
